
#include <hiredis/hiredis.h>  

#include "redis-handle.h"


redisContext* c  = NULL ;

int initRedisHandle()
{

    c = redisConnect("127.0.0.1", 6379);

    if( c-> err ){
        redisFree(c);  
        printf("Connect to redisServer faile\n");  
        return  -1 ;  
    }

    return 0 ;
}




int RedisPutInput( char *name , char **fnBam, int n)
{

    return 0 ;
}




/* 
 * Parameter Name : ListName =  name + "List"
 *           Vector :  struct { pos , offset ,len }
 * return -1  Exist push Error 
 */

int RedisPutValues( char *name  ,  idxVec *vector )
{

    return 0 ;
}


int RedisPutValue( char *name , int64_t  pos ,  long offset ,  long len )
{


    redisReply *reply;
    
    reply = redisCommand(c,"LPUSH  %s %lld,%ld,%ld",name,pos,offset,len);


    if(reply->type == REDIS_REPLY_ERROR ){
        fprintf(stderr,"Redis Reply Error:%s\n", reply->str);
        return  -1;
    }

    if(reply->type == REDIS_REPLY_INTEGER ){
        fprintf(stderr,"Redis Reply return integer:%lld\n",reply->integer);
        return  0 ;
    }
    
    return  0 ;
}



int destoryRedisHandle()
{
    redisFree(c);  
    return  0 ;
}



